class UserController {

    def index = {
        redirect(action:login)
    }

    def login = {
        if (!params.email)
            return
        
        def userInstance = User.findByEmail(params.email)

        if(!userInstance) {
            flash.message = "User not found with email ${params.email}"
        }
        else {
            session.user = userInstance
            redirect(controller:'dashboard', action:'index')
        }
    }

    def logout = {
        session.user = null
        redirect(action:'index')
    }
}
